﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using NOAH.CMS.Repository;
using NOAH.CMS.Cache;

public class NavigationController : Controller
{
    public ActionResult _Breadcrum()
    {
        List<Url> links = new List<Url>();
        string pageUrl = "";
        string Top = "";
        string id = string.Empty;
        pageUrl = Request.RawUrl;


        #region News
        if (pageUrl.Contains("/news/"))
        {
            Top = "Tin tức";


            NewsCategory currentCategory = new NewsCategory();
            List<NewsCategory> cates = new List<NewsCategory>();
            List<NewsCategory> allCates = new List<NewsCategory>();

            allCates = new NewsCategoryCacheLayer().GetAll();

            if (Request.Path.Contains("news/list"))
            {
                id = RouteData.Values["id"].ToString();
            }
            if (Request.Path.Contains("news/detail"))
            {
                id = RouteData.Values["cId"].ToString();
            }

            currentCategory = allCates.Find(p => p.ID.ToString() == id);

            cates.Add(currentCategory);
            int iCategoryTempID = currentCategory.ParentId;
            while (iCategoryTempID != 0)
            {
                NewsCategory categoryTemp = allCates.FirstOrDefault(x => x.ID == iCategoryTempID);
                if (categoryTemp != null)
                {
                    cates.Insert(0, categoryTemp);
                    iCategoryTempID = categoryTemp.ParentId;
                }
                else
                {
                    break;
                }
            }

            foreach (NewsCategory cate in cates)
            {
                links.Add(new Url { Title = cate.Name, Description = cate.SEOText, Link = cate.SEOLink });
            }

        }
        #endregion

        ViewBag.Top = Top;
        return View(links);
    }

}
